package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.StrategyCatalog;
import cn.wolfcode.luowowo.article.mapper.StrategyCatalogMapper;
import cn.wolfcode.luowowo.article.mapper.StrategyContentMapper;
import cn.wolfcode.luowowo.article.service.IStrategyCatalogService;
import cn.wolfcode.luowowo.common.query.StrategyCatalogQueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class StrategyCatalogServiceImpl implements IStrategyCatalogService {
    @Autowired
    private StrategyCatalogMapper strategyCatalogMapper;
    @Autowired
    private StrategyContentMapper strategyContentMapper;
    public PageInfo query(StrategyCatalogQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<StrategyCatalog> list = strategyCatalogMapper.queryForList(qo);
        return new PageInfo(list);
    }

    public void saveOrUpdate(StrategyCatalog strategyCatalog) {
        if(strategyCatalog.getId() == null){
            //添加
            strategyCatalogMapper.insert(strategyCatalog);

        }else{
            //修改
            strategyCatalogMapper.updateByPrimaryKey(strategyCatalog);
        }
    }

    public void deleteById(Long id) {
        strategyCatalogMapper.deleteByPrimaryKey(id);
    }

    public List<StrategyCatalog>  getByStrategyId(long strategyId) {

        return strategyCatalogMapper.selectByStrategyId(strategyId);
    }

    public List<StrategyCatalog> getCatalogsByDestId(Long id) {
        return strategyCatalogMapper.selectCatalogsByDestId(id);
    }

    public StrategyCatalog getById(Long catalogId) {
        return strategyCatalogMapper.selectByPrimaryKey(catalogId);
    }
}
